export default {
  data() {
    return {}
  },
  props: {
    dict: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  methods: {
    /**
     * 根据枚举值获取枚举名称
     */
    getDictNameByVal(val, propKey) {
      const list = this.dict[propKey]
      if (list) {
        const target = list.find(item => item.value == val)
        if (target) return target.name
      }

      return val
    },
    dictName(val, typeName) {
      return this.getDictNameByVal(val, typeName)
    },
    $toast(title) {
      uni.showToast({
        icon: 'none',
        title: title
      })
    },
    // 判断是否录入
    // 0 被认为是有效输入 '' 被认为是无效输入
    isValid(val) {
      return !!val || (typeof val == 'number' && val === 0)
    }
  }
}
